/*
 * Copyright (c) 2008, Xiong Yingfei, the University of Tokyo
 * All rights reserved.
 */
package ac.jp.u_tokyo.SyncLib.language;

import java.io.IOException;

import ac.jp.u_tokyo.SyncLib.language.factories.EDictMapCombinatorFactory;

public class EDictMapBody extends SyncBody
{

	SyncBody _inner;
	Const _dictCount;

	@Override
	public int getParaCount() throws EvaluationFailedException
	{
		return _inner.getParaCount();
	}
	
	static String getFactoryName() {
		return EDictMapCombinatorFactory.class.getName();
	}
	
	@Override
	public String writeInitializeFactory(Appendable sb,
			VarNameGenerator generator, ConstMapper constMap)
			throws EvaluationFailedException, IOException
	{
		String var = generator.getNextName();
		String inner = _inner.writeInitializeFactory(sb, generator, constMap);
		sb.append(getFactoryName()).append(" ").append(var).append(" = new ").append(getFactoryName()).append("(");
		sb.append(inner).append(", ");
		_dictCount.write(sb, constMap);
		StringBuilder s = new StringBuilder();
		_dictCount.write(s, constMap);
		sb.append(",").append(new Integer(_inner.getParaCount() - new Integer(s.toString())).toString());
		sb.append(");\n");;
		
		return var;
	}

	public EDictMapBody(int line, SyncBody inner, Const dictCount)
	{
		super(line);
		_inner = inner;
		_dictCount = dictCount;
	}

}
